// pages/project/project.js
  let startX = 0;//起始坐标
  let moveX = 0;//移动坐标
  let moveDistance = 0;//移动距离
Page({

  /**
   * 页面的初始数据
   */
  data: {
    itemTranfrom:'translateX(0)',//移动距离
    itemTransition:'',
    id:0,//移动单位
    projectList1:[
    {index:0,id:0,image:'/static/images/project/project.png',title:"农夫山泉矿泉水",price:2,quantity:2,Isdelete:false},
    {index:1,id:1,image:'/static/images/project/project.png',title:"农夫山泉矿泉水",price:2,quantity:3,Isdelete:false},
    {index:2,id:2,image:'/static/images/project/project.png',title:"农夫山泉矿泉水",price:2,quantity:8,Isdelete:false},
    {index:3,id:3,image:'/static/images/project/project.png',title:"农夫山泉矿泉水",price:2,quantity:10,Isdelete:false},
    ],
    projectList2:[
    {id:0,image:'/static/images/project/project.png',title:"农夫山泉矿泉水",price:2,quantity:2},
    {id:1,image:'/static/images/project/project.png',title:"农夫山泉矿泉水",price:2,quantity:2},
    {id:2,image:'/static/images/project/project.png',title:"农夫山泉矿泉水",price:2,quantity:2},
    ]
  },

  //跳转增加商品页面
  toAddProject(e){
    wx.navigateTo({
      url: '/pages/addProject/addProject',
    })
  },

  //跳转详情页面
  toDetail(e){
    console.log(e.target.dataset.id);
    console.log(e);

    wx.navigateTo({
      url: '/pages/detail/detail?'+'id='+e.target.dataset.id,
    })
  },

  //删除商品
  removeProject(e){
    let {projectList1,id,projectList2}=this.data
    var index = projectList1.findIndex((item)=>{return item.id== id})
    let project = projectList1.find((item)=>{return item.id== id})
    this.setData({
      [`projectList1[${index}].Isdelete`]:true
    })
    // console.log(index)
    projectList1.splice(index,1)
    projectList2.push(project)
    console.log(projectList1[index].Isdelete)
    setTimeout(() =>{
    this.setData({
      projectList1,
      projectList2
    })
    },1000)
  },

  //右滑
  handleTouchStart(event){
    // console.log(event)
    this.setData({
      itemTranfrom:`translateX(0 rpx)`,
      itemTransition:``,
      id:event.currentTarget.dataset.id
    })
    startX =event.touches[0].clientX;
    // console.log(startX,this.data.id)
  },
  handleTouchMove(event){
    // console.log(event,1)
    moveX =event.touches[0].clientX;
    moveDistance =startX - moveX;
    console.log(moveDistance)
    if (moveDistance <= 0) {
      return;
    }
    if (moveDistance >= 10) {
      moveDistance = 150
    }
    this.setData({
      itemTranfrom:`translateX(-${moveDistance}rpx)`
    })
    // console.log(this.data.itemTranfrom)

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})